home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Decision Cube / mxdimedt.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  4KB  |  149 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Borland Delphi Visual Component Library         }
  4. {                                                       }
  5. {       Copyright (c) 1997,99 Inprise Corporation       }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit mxdimedt;
  10.  
  11. interface
  12.  
  13. uses
  14.  Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics, DB,
  15.  Grids, Forms, ExtCtrls, mxConsts, mxgrid, mxdb, mxstore, mxdconst,
  16.  DsgnIntf, DsgnWnds;
  17.  
  18. type
  19.   TDimEditor = class(TDesignWindow)
  20.     DimListBox1: TListBox;
  21.     procedure DimListBox1Click(Sender: TObject);
  22.   private
  23.     myDims: TCollection;
  24.     myForm: TCustomForm;
  25.     myDesigner: IFormDesigner;
  26.     myObject: TComponent;
  27.     procedure UpdateSelection;
  28.     procedure UpdateList;
  29.   protected
  30.     function UniqueName(Component: TComponent): string; override;
  31.     procedure Activated; override;
  32.   public
  33.     procedure ComponentDeleted(Component: IPersistent); override;
  34.     procedure FormClosed(AForm: TCustomForm); override;
  35.     procedure FormModified; override;
  36.   end;
  37.  
  38. procedure ShowDisplayDimEditor(const Designer: IDesigner; anObject: TComponent);
  39.  
  40. implementation
  41.  
  42. {$R *.DFM}
  43.  
  44. procedure ShowDisplayDimEditor(const Designer: IDesigner; anObject: TComponent);
  45. var
  46.   aForm: TDimEditor;
  47. begin
  48.   aForm := TDimEditor.Create(application);
  49.   aForm.myDesigner := Designer as IFormDesigner;
  50.   aForm.myForm := Designer.Form;
  51.   aForm.myObject := anObject;
  52.   aForm.Caption := sGridDimOptions;
  53.   if (anObject is TDecisionGrid) then
  54.   begin
  55.     aForm.myDims := TDecisionGrid(anObject).Dimensions;
  56.     aForm.Caption := sGridDimSettings;
  57.   end
  58.   else if (anObject is TDecisionCube) then
  59.   begin
  60.     aForm.myDims := TDecisionCube(anObject).DimensionMap;
  61.     aForm.Caption := sCubeProperties;
  62.   end
  63.   else
  64.     Exit;
  65.   aForm.UpdateList;
  66.   aForm.Show;
  67. end;
  68.  
  69. procedure TDimEditor.Activated;
  70. var
  71.   Msg: TMessage;
  72. begin
  73.   Msg.Msg := WM_ACTIVATE;
  74.   Msg.WParam := 1;
  75.   myDesigner.IsDesignMsg(myForm, Msg);
  76.   UpdateSelection;
  77. end;
  78.  
  79. function TDimEditor.UniqueName(Component: TComponent): string;
  80. begin
  81.   Result := 'xxyss';
  82. end;
  83.  
  84. procedure TDimEditor.UpdateSelection;
  85. var
  86.   i: Integer;
  87.   bSelected: Boolean;
  88.   ComponentList: TDesignerSelectionList;
  89. begin
  90.   bSelected := False;
  91.   if not assigned(myDims) then Exit;
  92.   ComponentList := TDesignerSelectionList.Create;
  93.   try
  94.     with DimListBox1 do
  95.       for I := 0 to Items.Count - 1 do
  96.         if Selected[I] then
  97.         begin
  98.           bSelected := True;
  99.           ComponentList.Add(myDims.Items[i]);
  100.         end;
  101.   except
  102.     ComponentList.Free;
  103.     raise;
  104.   end;
  105.   if not bSelected then
  106.     ComponentList.Free
  107.   else
  108.     myDesigner.SetSelections(ComponentList);
  109. end;
  110.  
  111. procedure TDimEditor.UpdateList;
  112. var
  113.   i: Integer;
  114. begin
  115.   if not assigned(myDims) then Exit;
  116.   DimListBox1.Clear;
  117.   for I := 0 to myDims.count-1 do
  118.   begin
  119.     if (myObject is TDecisionGrid) then
  120.       DimListBox1.Items.Add(TDecisionGrid(myObject).Dimensions[i].FieldName)
  121.     else if (myObject is TDecisionCube) then
  122.       DimListBox1.Items.Add(TDecisionCube(myObject).DimensionMap[i].FieldName)
  123.     else
  124.       DimListBox1.Items.Add('# ' + inttostr(i + 1));
  125.   end;
  126. end;
  127. procedure TDimEditor.ComponentDeleted(Component: IPersistent);
  128. begin
  129.   if ExtractPersistent(Component) = myObject then Close;
  130. end;
  131.  
  132. procedure TDimEditor.FormClosed(AForm: TCustomForm);
  133. begin
  134.   if (myForm = AForm) then Close;
  135. end;
  136.  
  137. procedure TDimEditor.FormModified;
  138. begin
  139.   UpdateList;
  140.   UpdateSelection;
  141. end;
  142.  
  143. procedure TDimEditor.DimListBox1Click(Sender: TObject);
  144. begin
  145.   UpdateSelection;
  146. end;
  147.  
  148. end.
  149.